#include "BlockQueue_CP.hpp"
#include <iostream>
#include <string>
#include <unistd.h>
#include <ctime>

void *Productor(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    srand(time(0) ^ getpid());
    while (true)
    {
        int x = rand() % 10 + 1;
        bq->Equeue(x);
        std::cout << "Producter put, x = " << x << std::endl;
    }
}

void *Consumer(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    while (true)
    {
        int t;
        bq->Pop(&t);
        std::cout << "Consumer get, t = " << t << std::endl;
        usleep(1000);
    }
}

int main()
{
    BlockQueue<int> *bq = new BlockQueue<int>();
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, bq);
    pthread_create(&p, nullptr, Productor, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}